package com.durian.MPGenerator;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.config.rules.DateType;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;

import java.util.Collections;

/**
 * mybatisPlus代码生成器
 *
 * @author Durian
 * @date 2023/11/23
 */
public class MyGenerator {

    public static void main(String[] args) {
        FastAutoGenerator.create(
                "jdbc:mysql://120.27.245.192:3307/bookstore?serverTimezone=UTC",
                        "root",
                        "12138")
                .globalConfig(builder -> {
                    builder.author("Durian") // 设置作者
                            .dateType(DateType.TIME_PACK)//时间策略
                            .commentDate("yyyy-MM-dd")//注释日期
                            .outputDir("G:\\code\\SpringBoot_BookStore\\new\\java"); // 指定输出目录
                })
                .packageConfig(builder -> {
                    builder.parent("com.durian.MPGenerator") // 设置父包名
                            .entity("entity")
                            .service("service")
                            .serviceImpl("service.impl")
                            .mapper("com/durian/mapper")
                            .xml("mapper.xml")
                            .controller("controller")
                            .pathInfo(Collections.singletonMap(OutputFile.xml, "G:\\code\\SpringBoot_BookStore\\new\\resources\\mapper")); // 设置mapperXml生成路径
                })
                .strategyConfig(builder -> {
                    builder // 设置过滤表前缀// 设置需要生成的表名.addInclude("user","book").addTablePrefix("bookstore_")
                            .controllerBuilder()
                            .enableRestStyle()//开启restful风格
                            .entityBuilder()
                            .enableLombok()//开启 Lombok
                            .mapperBuilder()
                            .enableMapperAnnotation();//开启 @Mapper
                })
                .templateEngine(new FreemarkerTemplateEngine()) // 使用Freemarker引擎模板，默认的是Velocity引擎模板
                .execute();
    }
}
